<template>
	<view>
		<u-navbar title="入队申请"></u-navbar>
		<u-cell-group>
			<u-cell-item :title="join.talentName+' 申请加入 '+join.projectName" v-for="(join,index) in joins" :key="index"
				@click="clickInvite(index)" :value="join.type!=null?'已处理':''" :arrow="join.type==null">
			</u-cell-item>
		</u-cell-group>
		<u-popup v-model="show" mode="bottom">
			<u-button type="primary" class="u-m-l-20 u-m-r-20 u-m-t-50" @click="clickProcess(0)">同意</u-button>
			<u-button type="error" class="u-m-l-20 u-m-r-20 u-m-t-25 u-m-b-50" @click="clickProcess(1)">拒绝</u-button>
		</u-popup>
	</view>
</template>

<script>
	export default {
		async onLoad() {
			let [err, res] = await this.$to(this.$api.get({
				url: "/userinfo/joins"
			}));
			this.joins = res.data;
		},
		data() {
			return {
				joins: [],
				show: false,
				cur: null
			}
		},
		methods: {
			clickInvite(index) {
				this.cur = this.joins[index];
				if (this.cur.type != null) return;
				this.show = true;
			},
			async clickProcess(type) {
				let [err, res] = await this.$to(this.$api.post({
					url: "/userinfo/join_process",
					data: {
						joinId: this.cur.joinId,
						type: type
					}
				}));
				if (!err && res.code == 200) {
					this.cur.type = type;
					this.show = false;
					this.$toast(res.msg);
				} else {
					this.$toast(err ? null : res.msg);
				}
			}
		}
	}
</script>

<style>

</style>
